﻿using Masuit.Tools.Reflection;
using MetaView.Mvvm.Apis.Auth.Param;
using MetaView.Mvvm.Apis.Common;
using System.Configuration;
using System.IO;
using System.Text.Json;

namespace MetaView.Mvvm.Apis.User
{
    public class AuthApi
    {
        public async Task<CommonResult<Object>> doLogin(AuthAccountPasswordLoginParam authAccountPasswordLoginParam)
        {
            // 根据配置决定是否使用mock数据
            if (CommonMock.useMockData)
            {
                // 这里是mock数据
                string jsonFilePath = "MockData.json";
                string jsonContent = File.ReadAllText(jsonFilePath);

                // 反序列化 JSON 数据 
                var data = JsonSerializer.Deserialize<object[]>(jsonContent);
                return (CommonResult<object>)data.GetField("doLogin_success");
            }
            else
            {
                // 这里是api数据
                return CommonResult<Object>.Custom(200, "暂未实现", null);
            }            
        }

        //public async Task<CommonResult<Object>> getLoginUser(AuthAccountPasswordRegisterParam authAccountPasswordRegisterParam) 
        //{
            
        //}

        public async Task<CommonResult<Object>> doLogout()
        {
            // 根据配置决定是否使用mock数据
            if (CommonMock.useMockData)
            {
                // 这里是mock数据
                string jsonFilePath = "MockData.json";
                string jsonContent = File.ReadAllText(jsonFilePath);

                // 反序列化 JSON 数据 
                var data = JsonSerializer.Deserialize<object[]>(jsonContent);
                return (CommonResult<object>)data.GetField("doLogout_success");
            }
            else
            {
                // 这里是api数据
                return CommonResult<Object>.Custom(200, "暂未实现", null);
            }
        }
    }
}
